package com.ysd.lis.service.eq.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.eq.*;
import com.ysd.lis.mapper.eq.EqSpotcheckTaskEqMapper;
import com.ysd.lis.service.eq.EqSpotcheckTaskEqService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 点检记录设备 服务实现类
 * </p>
 *
 * @author WH
 * @since 2024-08-26
 */
@Service
public class EqSpotcheckTaskEqServiceImpl extends ServiceImpl<EqSpotcheckTaskEqMapper, EqSpotcheckTaskEq> implements EqSpotcheckTaskEqService {

    @Autowired
    private EqSpotcheckTaskEqMapper eqSpotcheckTaskEqMapper;

    @Override
    public Result findSpotcheckTaskEqList(EqSpotcheckTaskEq eqSpotcheckTaskEq) {
        MPJLambdaWrapper<EqSpotcheckTaskEq> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.distinct();
        queryWrapper.selectAll(EqSpotcheckTaskEq.class);
        queryWrapper.selectCollection(EqSpotcheckTaskEqSt.class, EqSpotcheckTaskEq::getSpotcheckTaskEqStList);
        queryWrapper.leftJoin(EqSpotcheckTaskEqSt.class, EqSpotcheckTaskEqSt::getTaskEqId, EqSpotcheckTaskEq::getId);

        queryWrapper.eq(StringUtils.isNotBlank(eqSpotcheckTaskEq.getTaskId()), EqSpotcheckTaskEq::getTaskId, eqSpotcheckTaskEq.getTaskId());
        queryWrapper.eq(EqSpotcheckTaskEq::getDelFlag, 0);
        List<EqSpotcheckTaskEq> eqPatrolTaskEqs = eqSpotcheckTaskEqMapper.selectJoinList(EqSpotcheckTaskEq.class, queryWrapper);
        return Result.succ(1, "查询成功！", eqPatrolTaskEqs);
    }

    @Override
    public Result findSpotcheckTaskByEqId(EqSpotcheckTaskEq eqSpotcheckTaskEq) {
        MPJLambdaWrapper<EqSpotcheckTaskEq> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.distinct();
        queryWrapper.selectAll(EqSpotcheckTaskEq.class);
        queryWrapper.selectAs(EqSpotcheckTask::getName,EqSpotcheckTaskEq::getTaskName);
        queryWrapper.selectCollection(EqSpotcheckTaskEqSt.class, EqSpotcheckTaskEq::getSpotcheckTaskEqStList);
        queryWrapper.leftJoin(EqSpotcheckTask.class, EqSpotcheckTask::getId, EqSpotcheckTaskEq::getTaskId);
        queryWrapper.leftJoin(EqSpotcheckTaskEqSt.class, EqSpotcheckTaskEqSt::getTaskEqId, EqSpotcheckTaskEq::getId);

        queryWrapper.eq(EqSpotcheckTaskEq::getEqId,eqSpotcheckTaskEq.getEqId());
        queryWrapper.eq(EqSpotcheckTaskEq::getDelFlag,0);
        List<EqSpotcheckTaskEq> eqPatrolTaskEqs = eqSpotcheckTaskEqMapper.selectJoinList(EqSpotcheckTaskEq.class, queryWrapper);
        return Result.succ(1, "查询成功！", eqPatrolTaskEqs);
    }
}
